<?php

use Nette\Security as NS;

/**
 * Users authenticator.
 */
class Authenticator extends Nette\Object implements NS\IAuthenticator
{

    /**
     * Performs an authentication
     * @param  array
     * @return Nette\Security\Identity
     * @throws Nette\Security\AuthenticationException
     */
    public function authenticate(array $credentials)
    {
        list($username, $password) = $credentials;
        $cred = Nette\Utils\Neon::decode(file_get_contents(APP_DIR . '/config/app.neon'));
        $cred = $cred['adminCredentials'];

        if (strtolower($username) != $cred['user'] || $password != $cred['password'])
        {
            throw new NS\AuthenticationException("Neplatné přihlašovací údaje.", self::IDENTITY_NOT_FOUND);
        }
        return new NS\Identity(1, 'admin');
    }

}
